<template>
  <div>
    <el-row :gutter="20" type="flex">
      <el-col :span="6">
        <el-input
          placeholder="请输入文章标题"
          v-model="listQueryIn.subjectsName"
          clearable
        >
        </el-input>
      </el-col>
      <el-col :span="12">
        <el-button type="custom" @click="refreshList()" plain>搜索</el-button>
        <el-button
          type="primary"
          @click="handleBatchClassify()"
          :disabled="multipleSelection.length == 0"
          >分类</el-button
        >
        <el-button
          type="danger"
          @click="handleBatchDelete()"
          :disabled="multipleSelection.length == 0"
          >删除</el-button
        >
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      multipleSelection: [],
      listQueryIn: {
        subjectsName: '',
      },
    }
  },
  mounted() {
    this.$bus.$on('testSubjectsErrorArr', (v) => {
      this.multipleSelection = v
    })
  },
  beforeDestroy() {
    this.$bus.$off('testSubjectsErrorArr')
  },
  methods: {
    refreshList() {
      this.$bus.$emit('refreshTestErrorClassifyList', this.listQueryIn)
    },
    //批量删除
    handleBatchDelete() {
      if (!this.multipleSelection.length) {
        this.warnMsg('请选择要删除的数据')
        return
      }
      this.deleteTips(this.deleteAll)
    },
    //批量删除
    async deleteAll() {
      let ids = this.multipleSelection.map((v) => v.id)
      await this.$store.dispatch('deleteBatchTestSubjectsError', ids)
      this.$bus.$emit('clearSelected')
      this.multipleSelection = []
    },
    handleBatchClassify() {
      let ids = this.multipleSelection.map((v) => v.id)
      this.$bus.$emit('showDialogTestErrorClassify', ids)
      this.multipleSelection = []
    },
  },
}
</script>